/*
* This file is a part of the open-eBackup project.
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at
* http://mozilla.org/MPL/2.0/.
*
* Copyright (c) [2024] Huawei Technologies Co.,Ltd.
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*/
#ifndef LIVE_MOUNT_SERVICE_JOB_H
#define LIVE_MOUNT_SERVICE_JOB_H

#include <vector>
#include "JobCommonInfo.h"
#include "JobMgr.h"
#include "BasicJob.h"
#include "define/Defines.h"
#include "define/Types.h"
#include "common/JsonHelper.h"

class LivemountServiceJob : public BasicJob {
public:
    LivemountServiceJob() {}
    ~LivemountServiceJob();
    int CheckBackupJobType();
    EXTER_ATTACK int PrerequisiteJob() override;
    EXTER_ATTACK int GenerateSubJob() override;
    EXTER_ATTACK int ExecuteSubJob() override;
    EXTER_ATTACK int PostJob() override;

private:
    struct CifsAdvanceParams {
        int domainType;
        std::string shareName;
        std::vector<std::string> usernames;
        BEGIN_SERIAL_MEMEBER
        SERIAL_MEMBER_TO_SPECIFIED_NAME(domainType, domainType);
        SERIAL_MEMBER_TO_SPECIFIED_NAME(shareName, shareName);
        SERIAL_MEMBER_TO_SPECIFIED_NAME(usernames, usernames);
        END_SERIAL_MEMEBER
    };

    struct FileSystemShareInfo {
        std::string accessPermission;
        CifsAdvanceParams advanceParams;
        std::string fileSystemName;
        int type;
        BEGIN_SERIAL_MEMEBER
        SERIAL_MEMBER_TO_SPECIFIED_NAME(accessPermission, accessPermission);
        SERIAL_MEMBER_TO_SPECIFIED_NAME(advanceParams, advanceParams);
        SERIAL_MEMBER_TO_SPECIFIED_NAME(fileSystemName, fileSystemName);
        SERIAL_MEMBER_TO_SPECIFIED_NAME(type, type);
        END_SERIAL_MEMEBER
    };

    struct LiveMountStorageRepositoryExtendInfo {
        FileSystemShareInfo fileSystemShareInfo;
        std::string manualMount;

        BEGIN_SERIAL_MEMEBER
        SERIAL_MEMBER_TO_SPECIFIED_NAME(fileSystemShareInfo, fileSystemShareInfo);
        SERIAL_MEMBER_TO_SPECIFIED_NAME(manualMount, manualMount);
        END_SERIAL_MEMEBER
    };

    // 外层的extendInfo 的filesystemInfo 结构体不一样
    struct FileSystemShareInfoOuter {
        int accessPermission;
        std::string fileSystemName;
        int type;
        BEGIN_SERIAL_MEMEBER
        SERIAL_MEMBER_TO_SPECIFIED_NAME(accessPermission, accessPermission);
        SERIAL_MEMBER_TO_SPECIFIED_NAME(fileSystemName, fileSystemName);
        SERIAL_MEMBER_TO_SPECIFIED_NAME(type, type);
        END_SERIAL_MEMEBER
    };

    struct LivemountExtendPerformance {
        int fileSystemKeepTime;
        BEGIN_SERIAL_MEMEBER
        SERIAL_MEMBER_TO_SPECIFIED_NAME(fileSystemKeepTime, fileSystemKeepTime);
        END_SERIAL_MEMEBER
    };

    struct LivemountJobExtendInfo {
        std::vector<FileSystemShareInfoOuter> fileSystemShareInfo;
        LivemountExtendPerformance performance;
        BEGIN_SERIAL_MEMEBER
        SERIAL_MEMBER_TO_SPECIFIED_NAME(fileSystemShareInfo, fileSystemShareInfo);
        SERIAL_MEMBER_TO_SPECIFIED_NAME(performance, performance);
        END_SERIAL_MEMEBER
    };

    int PrerequisiteJobInner() const;
    int GenerateSubJobInner();
    int ExecuteSubJobInner();
    int PostJobInner() const;
    int IdentifyRepos();
    int ReportMountLabel();
    int HandleProcessForCyberEngine(int maxRetryCnt);

    std::shared_ptr<AppProtect::LivemountJob> m_livemountPara = nullptr;
    std::vector<std::shared_ptr<AppProtect::StorageRepository>> m_dataRepos {};
    bool GetJobInfoBody();
};

#endif